package mysql

import (
	"beergo/lib/tool"
	"fmt"
)

func GenerateConfig(c *Creator) {
	for _, field := range c.Fields {
		field.CreateConfig()
	}
	CreateOrmConfigFile(c)
}
func createModelFile(c *Creator, content []byte) {
	path := fmt.Sprintf(
		"%s/app/%s/models/%s_.go",
		root, c.Table.Path, c.Table.Name)
	tool.CreateFile(path, content)
}
func createCrudFile(c *Creator, content []byte) {
	path := fmt.Sprintf(
		"%s/app/%s/models/%s_CURD.go",
		root, c.Table.Path, c.Table.Name)
	tool.CreateFile(path, content)
}

/***************************Model创建*********************************/
type OrmField struct {
	Name string
	Type string
	Tags string
}

func CreateModel(creator *Creator) {
	data := twigger.Render("/mysql/model.twig", creator)
	createModelFile(creator, []byte(data))
}

func CreateCrud(creator *Creator) {
	data := twigger.Render("/mysql/model_func.twig", creator)
	createCrudFile(creator, []byte(data))
}
